/* ===============================================
 *                用户权限相关
 * =============================================== */
import Http from '@/http'
import API from '@/api'
import Store from '@/store'
import Cookie from '@/utils/cookie'
const Auth = {

    /**
     * 登录 by 验证码
     * @param params
     */
    loginByCode:function (params,callback) {
      return Http.getModel(API.login_by_code, params)
    },
    /**
     * 登录 by 密码
     * @param params
     */
    loginByPwd:function (params) {
        return Http.getModel(API.login_by_pwd, params,false)
    },

    /**
     * 用户注册
     * @param params
     */
    register:function (params,callback) {
      return Http.getModel(API.do_register, params)

    },
    /**
     * 检查登录状况
     * @param params
     */
    isLogin:function (params) {
        let user = this.getUser()
        if(user&&user.id){
            return true
        }else{
            return false
        }
    },
    /**
     * 退出登录
     */
    exit: function () {
        Cookie.set("auth_token",null)
        Store.commit("SET_USER",{})
    },
    /**
     * 获取登录用户信息
     */
    getUserByToken: function (token) {
        return Http.getModel(API.get_user_by_token, {token:token})
    },
    getUser: function () {
        var that = this
        return Store.getters.user
    },




}

export default  Auth;
